<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@include file="../commons/head.jsp"%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>KanKan	Book</title>
<link rel="stylesheet" type="text/css" href="${domainStaticUrl}/css/style.css" />
<link rel="shortcut icon" href="${domainStaticUrl}/images/inform.ico" type="image/x-icon">
<script type="text/javascript" src="${domainStaticUrl}/js/jquery-1.8.2.js"></script>
<script type="text/javascript" src="${domainStaticUrl}/layer/layer.js"></script>
</head>
<body>
<div id="wrap">

       <div class="header">
       		<div class="logo"><a href="index.html"><img src="${domainStaticUrl}/images/logo.gif" alt="" title="" border="0" /></a></div>
        <div id="menu">
             <ul>                                                                       
            <li class="selected"><a href="/">主页</a></li>
            <li><a href="${domainUrl}/category.jsp">书籍</a></li>
            <li><a href="${domainUrl}/specials.jsp">分类</a></li>
            <li><a href="${domainUrl}/about.jsp">关于我们</a></li>
             <c:if test="${user1==null }">
		            	<li><a href="${domainUrl}/toLogin">登录</a></li>
		            	<li><a href="${domainUrl}/toRegin">注册</a></li>
	            </c:if>
	            </ul>
	             <c:if test="${user1!=null }">
	            	<div style="margin-right:-250px ;float: right">
	            	
	            		<span id="tips" style="color:white;font-size: 16px;">欢迎:<a>${user1.userName }</a></span>&nbsp;&nbsp;&nbsp;
	            		<span id="loginOut" style="font-size: 15px;color: red;cursor:pointer"><a href="loginOut.tushu" style="text-decoration:none;">注销</a></span>
	            	</div>
	            </c:if>
        </div>     
            
            
       </div>
       
       
       <div class="center_content">
       	<div class="left_content">
            <div class="title"><span class="title_icon"><img src="${domainStaticUrl}/images/bullet1.gif" alt="" title="" /></span>购物车</div>
        
        	<div class="feat_prod_box_details">
           <!-- 购物车详情 -->
            <table id="cart_table" class="cart_table">
                  
                
            </table>
            <a href="${domainUrl}/settlement" class="checkout">去结算 &gt;</a>
            

             
            
            </div>	
            
              

            

            
        <div class="clear"></div>
        </div><!--end of left content-->
        
        
        <div class="right_content">
        	<div class="languages_box">
            <span class="red">语言:</span>
            <a href="#" class="selected"><img src="${domainStaticUrl}/images/gb.gif" alt="" title="" border="0" /></a>
            <a href="#"><img src="${domainStaticUrl}/images/fr.gif" alt="" title="" border="0" /></a>
            <a href="#"><img src="${domainStaticUrl}/images/de.gif" alt="" title="" border="0" /></a>
            </div>
                <div class="currency">
                <span class="red">货币: </span>
                <a href="#">DOLLAR</a>
                <a href="#" class="selected">RMB</a>
                </div>
                
                
              <div class="cart">
                  <div class="title"><span class="title_icon"><img src="${domainStaticUrl}/images/cart.gif" alt="" title="" /></span>My cart</div>
                  <div class="home_cart_content">
                  <span id="cartNum"></span>
                  <span class="red"> 件商品 |  总计:<span id="cartCountPrice"></span> ￥</span>
                  </div>
                  <input id="cart" style="color:white;background: green;margin-top: 13px;cursor:pointer;border: 0px" type="button" value="购物车" />
              
              </div>
                       
            	
        
        
             <div class="title"><span class="title_icon"><img src="${domainStaticUrl}/images/bullet3.gif" alt="" title="" /></span>关于我们的书店</div>
             <div class="about">
             <p>
             <img src="${domainStaticUrl}/images/about.gif" alt="" title="" class="right" />
             	每个人的生命中，都有最艰难的那一年，将人生变得美好而辽阔。 一个失去了一切的人，如何重新找到牵挂，书，爱情，宴会和欢笑，以及一切美好生活。 
             </p>
             
             </div>
             
             <div class="right_box">
             
             	<div class="title"><span class="title_icon"><img src="${domainStaticUrl}/images/bullet4.gif" alt="" title="" /></span>促销</div>
                    <div id="endBook">
	                                
             		</div>              
             
             </div>
             
             <div class="right_box">
             
             	<a href="${domainUrl}/specials"><div class="title"><span class="title_icon"><img src="${domainStaticUrl}/images/bullet5.gif" alt="" title="" /></span>分类</div></a>
                
                <ul class="list">
                <li><a href="#">政治</a></li>
                <li><a href="#">经济</a></li>
                <li><a href="#">历史</a></li>
                <li><a href="#">科学</a></li>
                <li><a href="#">文学</a></li>
                <li><a href="#">体育</a></li>                                         
                </ul>
                
             	<div class="title"><span class="title_icon"><img src="${domainStaticUrl}/images/bullet6.gif" alt="" title="" /></span>合作伙伴</div>
                
                <ul class="list">
                <li><a href="#">宇宙 </a></li>
                <li><a href="#">星系</a></li>
                <li><a href="#">银河</a></li>
                <li><a href="#">太阳</a></li>
                <li><a href="#">地球</a></li>
                <li><a href="#">月亮</a></li>
                <li><a href="#">星星</a></li>
                <li><a href="#">海洋</a></li>
                <li><a href="#">陆地</a></li>                              
                </ul>      
             
             </div>         
             
        
        </div><!--end of right content-->
        
        
       
       
       <div class="clear"></div>
       </div><!--end of center content-->
       
              
        <div class="footer">
       	<div class="left_footer">
       		<img src="${domainStaticUrl}/images/footer_logo.gif" alt="" title="" /><br />
       		
       	</div>
        <div class="right_footer">
        	<a href="${doaminUrl}/">主页</a>
            <a href="${domainUrl}/about">关于我们</a>
            <a href="${domainUrl}/category">书籍</a>
            <a href="${domainUrl}/specials">特别的书</a>
        </div>
        
       
       </div>
   

</div>

</body>

<script type="text/javascript">
$(document).ready(function(){
/*最后图书的ajax查询  */
	$.post("book/findBook", {"tag" : "","currentNum" : 1}, function(r) {
		var obj=eval("("+r+")");
		var listPage=obj.listPage;
		//得到按钮
		var endBook=$("#endBook");
		var endBookIn="";
	 	$.each(listPage,function(index,obj){
	 		if(index<3){
	 			endBookIn+="<div class='new_prod_box'><a href='findBookProduct.tushu?bookId="+listPage[index].bookId+"'>"+listPage[index].bookName+
				  "</a><div class='new_prod_bg'><span class='new_icon'><img src='${domainStaticUrl}/images/promo_icon.gif' alt='' title='' /></span><a href='book/findBookProduct?bookId="+listPage[index].bookId+"'><img src='${domainStaticUrl}/images/thumb2.gif' alt='' title='' class='thumb' border='0' /></a></div></div>"
				   
	 		}else{
	 			 return false;
	 		}
		}); 
		endBook.html(endBookIn);
	});
	
	/*判断用户登录了吗   然后查询购物车列表  */
	var user1='<%=session.getAttribute("user1")%>';
	if("null"!=user1){
		$.post("cart/cart",{},function(r){
			creatHtml(r);
		});
	}
});


$("#cart").click(function(){
		$.post("cart/cart",{},function(r){
			var obj=eval("("+r+")");
			var cartString=obj.cartString;
			if(cartString=="未登录,请先登录!"){
				alert(cartString);
				location.href="${domainUrl}/toLogin";
			}else{
				location.href="${domainUrl}/cart/lookCart"
			}
		})
	});
	
	
function creatHtml(r){
		var obj=eval("("+r+")");
		if(obj.cartString!=""){
			layer.alert(obj.cartString, {
				  skin: 'layui-layer-molv' //样式类名
				  ,closeBtn: 0
				});
		}
		var cart_table=$("#cart_table");
		var cart_tablein="<tr class='cart_title'><td>封	面</td><td>书	名</td><td>作	者</td><td>数	量</td><td>单	价</td></tr>";
		var cartNum=$("#cartNum");
		var cartCountPrice=$("#cartCountPrice");
			var cartNum2=obj.cartNum;
			var cartCountPrice2=obj.cartCountPrice;
			cartNum.html(cartNum2);
			cartCountPrice.html(cartCountPrice2);
			$.each(obj.list,function(index,obj){
				cart_tablein+="<tr><td><img src='images/cart_thumb.gif' border='0' class='cart_thumb' /></td><td>"+obj.bookName+
				"</td><td>"+obj.bookWriter+
				"</td><td>"+obj.bookNum+
				"</td><td>"+obj.bookPrice+"</td><td><img id='deleteId"+index+"' style='cursor:pointer;' src='${domainStaticUrl}/images/Delete.png' /></td></tr>"
			});
			cart_tablein+="<tr><td colspan='4' class='cart_total'><span class='red' style='font-size:15px;'>总额:</span></td><td style='color:red;font-size:13px'>"+cartCountPrice2+"￥</td></tr>"
			cart_table.html(cart_tablein);
			
			$.each(obj.list,function(index,obj){
				var deleteId="deleteId"+index;
				$("#"+deleteId).click(function(){
					ajaxSubmit(obj.cartId);
				});
			});
	}

function ajaxSubmit(cartId){
	$.post("deleteProduct.tushu",{"cartId":cartId},function(r){
		creatHtml(r);
	})
}

</script>

</html>